package sdstcom.lbq.one.lbq.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.LinkedList;

import sdstcom.lbq.one.R;
import sdstcom.lbq.one.lbq.Databeans.DbBean;

/**
 * Created by Administrator on 2017/1/13 0013.
 */

public class CollectAdapter extends BaseAdapter {
    private ArrayList<DbBean> list;
    private Context context;
    private LayoutInflater inflater;
    private String type;

    public CollectAdapter(ArrayList<DbBean> list, Context context) {
        this.list = list;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {

        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null)
        {
          convertView=inflater.inflate(R.layout.collect_item,parent,false);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        else
        {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.title.setText(list.get(position).getTitle());
        switch (list.get(position).getType())
        {
            case "essay":
                holder.type.setText("文章");
                break;
            case "wenda":
                holder.type.setText("问答");
                break;
            case "music":
                holder.type.setText("音乐");
                break;
            case "movie":
                holder.type.setText("视频");
                break;
        }
        return convertView;
    }
    public static class ViewHolder
    {
        TextView type;
        TextView title;
        public ViewHolder(View convertView) {
            type= (TextView) convertView.findViewById(R.id.collect_item_type);
            title= (TextView) convertView.findViewById(R.id.collect_item_title);
        }
    }
}
